package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.dto.IllnessDto;
import cn.jiahua.hospital.mapper.IllnessMapper;
import cn.jiahua.hospital.pojo.Illness;
import cn.jiahua.hospital.service.IllnessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

@Service
public class IllnessServiceImpl implements IllnessService {

    @Autowired
    private IllnessMapper illnessMapper;

    @Override
    public IllnessDto getIllnessById(Integer id) {
        return illnessMapper.getIllnessById(id);
    }

    @Override
    public List<Illness> getIllnessListByMap(Map<String, Object> param) {
        return illnessMapper.getIllnessListByMap(param);
    }

    @Override
    public Integer getIllnessCountByMap(Map<String, Object> param) {
        return illnessMapper.getIllnessCountByMap(param);
    }

    @Override
    public List<IllnessDto> getIllnessListByMap1(Map<String, Object> param) {
        return illnessMapper.getIllnessListByMap1(param);
    }

    @Override
    public Integer getIllnessCountByMap1(Map<String, Object> param) {
        return illnessMapper.getIllnessCountByMap1(param);
    }

    @Override
    public Integer qdtxAddIllness(Illness illness) {
        return illnessMapper.insertIllness(illness);
    }

    @Override
    public Integer qdtxModifyIllness(Illness illness) {
        return illnessMapper.updateIllness(illness);
    }

    @Override
    public Integer qdtxDeleteIllnessById(Integer id) {
        return illnessMapper.deleteIllnessById(id);
    }

    @Override
    public Integer qdtxBatchDeleteIllness(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return illnessMapper.batchDeleteIllness(param);
    }

    @Override
    public Page<Illness> queryIllnessPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = illnessMapper.getIllnessCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Illness> illnessList = illnessMapper.getIllnessListByMap(param);
        page.setList(illnessList);
        return page;
    }
}